package com.ruoyi.fetv.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.fetv.controller.vo.comment.AddReq;
import com.ruoyi.fetv.controller.vo.comment.EditReq;
import com.ruoyi.fetv.domain.FetvComment;
import com.ruoyi.fetv.service.IFetvCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 资讯评论Controller
 *
 * @author Jack
 * @date 2023-03-07
 */
@Api(value = "/fetv/comment", tags = {"资讯评论管理"})
@RestController
@RequestMapping("/fetv/comment")
@Validated
@AutoDict
public class FetvCommentController extends BaseController {
    @Autowired
    private IFetvCommentService fetvCommentService;

    /**
     * 查询资讯评论列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "FetvComment", name = "fetvComment", value = "", required = true)
    })
    @ApiOperation(value = "查询资讯评论列表", notes = "查询资讯评论列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('fetv:comment:list')")
    @GetMapping("/list")
    public TableDataInfo<List<FetvComment>> list(FetvComment fetvComment) {
        startPage();
        List<FetvComment> list = fetvCommentService.selectFetvCommentList(fetvComment);
        return getDataTable(list);
    }


    /**
     * 获取资讯评论详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "获取资讯评论详细信息", notes = "获取资讯评论详细信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = FetvComment.class)
    @PreAuthorize("@ss.hasPermi('fetv:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        FetvComment data = fetvCommentService.selectFetvCommentById(id);
        if (data == null) {
            throw new ServiceException("不存在的ID");
        }
        return success(data);
    }

    /**
     * 新增资讯评论
     */

    @ApiOperation(value = "新增资讯评论", notes = "新增资讯评论", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('fetv:comment:add')")
    @Log(title = "资讯评论", businessType = BusinessType.INSERT)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @PostMapping
    public AjaxResult add(@ApiParam(name = "fetvComment", value = "资讯评论", required = true) @RequestBody @Valid AddReq fetvComment) {
        return toAjax(fetvCommentService.insertFetvComment(fetvComment));
    }

    /**
     * 修改资讯评论
     */

    @ApiOperation(value = "修改资讯评论", notes = "修改资讯评论", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('fetv:comment:edit')")
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @Log(title = "资讯评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name = "fetvComment", value = "资讯评论", required = true) @RequestBody @Valid EditReq fetvComment) {
        return toAjax(fetvCommentService.updateFetvComment(fetvComment));
    }

    /**
     * 删除资讯评论
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Long[]", name = "ids", value = "", required = true)
    })
    @ApiOperation(value = "删除资讯评论", notes = "删除资讯评论", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('fetv:comment:remove')")
    @Log(title = "资讯评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fetvCommentService.deleteFetvCommentByIds(ids));
    }
}
